import { defineConfig, mergeConfig, loadEnv } from "vite";
import type { UserConfig, ConfigEnv } from "vite";
import viteBaseConfig from "./vite.config.base";
import viteDevConfig from "./vite.config.dev";
import viteProdConfig from "./vite.config.prod";

// https://vite.dev/config/
const root = process.cwd();
const useResolve = {
  build() {
    return mergeConfig(viteBaseConfig, viteProdConfig);
  },
  serve() {
    return mergeConfig(viteBaseConfig, viteDevConfig);
  },
};
export default defineConfig(({ command, mode }: ConfigEnv): UserConfig => {
  const env = loadEnv(mode, root);
  console.log(env, mode, process.env.NODE_ENV, ">>>>>>>env");
  return useResolve[command]();
});
